﻿Public Class ProjectImageManageForm

    Public Sub New()

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

    End Sub

    '是否修改
    Public UpdateFlag As Boolean = False

    Public Sub New(ByVal pi As ProjectItem)
        MyClass.New()
        _pi = pi
    End Sub

    Private _pi As ProjectItem = Nothing

    Private Sub ProjectImageManageForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadImages()
    End Sub

    Private Sub LoadImages()
        FlowLayoutPanel1.Controls.Clear()
        For Each pii As ProjectImageItem In _pi.imageList
            Dim ctl As New ProjectImageControl(pii, _pi)
            AddHandler ctl.ImageDeleteEvent, AddressOf LayDelete
            AddHandler ctl.ImageModifyEvent, AddressOf LayUpdate
            Me.FlowLayoutPanel1.Controls.Add(ctl)
            ctl.Show()
        Next
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim frm As New ProjectImageAddForm(_pi.ProjectID)
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim ctl As New ProjectImageControl(frm.pii, _pi)
            AddHandler ctl.ImageDeleteEvent, AddressOf LayDelete
            AddHandler ctl.ImageModifyEvent, AddressOf LayUpdate
            Me.FlowLayoutPanel1.Controls.Add(ctl)
            ctl.Show()
            'MainForm.RefeshCurrentProjectInfo()
            UpdateFlag = True
        End If
    End Sub

    Private Sub LayDelete(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim c As ProjectImageControl = sender
        Me.FlowLayoutPanel1.Controls.Remove(sender)
        'MainForm.RefeshCurrentProjectInfo()
        UpdateFlag = True
    End Sub


    Private Sub LayUpdate(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CType(sender, ProjectImageControl).refreshControl()
        UpdateFlag = True
    End Sub



    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

End Class